class pn(object):
    n = 0

    @classmethod
    def initial(cls, ipt):
        Pn = cls()
        Pn.a = ipt
        Pn.n = len(ipt)
        return Pn
        #初始化类，a为列表，a[i]储存x^i的系数，n为多项式的最高次
        #即Pn = a[0] + a[1] * x + a[2] * x^2 + ... + a[n] * x^n

    @property
    def a(self):
        return self._a

    @a.setter
    def a(self, a):
        self._a = a

    def __add__(self, v):
        max_len = max(self.n, v.n)
        ans = [0] * max_len
        for i in range(max_len):
            if i < self.n:
                ans[i] += self.a[i]
            if i < v.n:
                ans[i] += v.a[i]
        # print(ans)
        return pn.initial(ans)

    def __sub__(self, v):
        max_len = max(self.n, v.n)
        ans = [0] * max_len
        for i in range(max_len):
            if i < self.n:
                ans[i] += self.a[i]
            if i < v.n:
                ans[i] -= v.a[i]
        
        return pn.initial(ans)

    def __mul__(self, v):
        max_len = self.n + v.n
        ans = [0] * max_len
        for i in range(self.n):
            for j in range(v.n):
                ans[i+j] = self.a[i] * v.a[j]
        return pn.initial(ans)
        
    def printout(self):
        res = "answer is "
        # print(self.n)
        print(len(self.a))
        for i in range(self.n):
            # print("1")
            if self.a[i] > 0 and i > 0:
                
                res += f"+{round(self.a[i], 2)}x^{i}"
            elif self.a[i] < 0:
                res += f"{round(self.a[i], 2)}x^{i}" 
            elif i == 0 and self.a[i] != 0:
                res += f"{round(self.a[i], 2)}"   
        return res


if __name__ == '__main__':
    a = [1,2,3]
    b = [2,0,1]
    U = pn.initial(a)
    V = pn.initial(b)
    W = U * V
    print(W.printout())